Frequently Asked Questions

Program #2


How do I exit the program?

You can exit your program by calling

System.exit(0);

For those interested, you can read more about this method in the documentation for the System class.


How do I convert a String to a double (just like I convert a String into an int with Integer.parseInt())?

Use the static method of the Double class and pass in the String. For example,

String numString = "5.321";

double numDouble = Double.parseDouble(numString);

See the documentation for more info.


How much error checking do I need to do?

You may assume that the grader will enter doubles when doubles are expected, integers when integers expected, etc.


How much formatting do I need to do?

You are not required to print out currency in nice 2-decimal place format. If price is stored in a double, print it out using the default String representation of the primitive double. You also don't need to format into columns the fields of the Book class when the toString method is called. You can print each field (title, price, etc) on a new line if desired.